//app.js
var myLon,myLat;
App({
    onLaunch: function () {
        //调用API从本地缓存中获取数据
        var logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs);
        wx.getLocation({
            type: 'wgs84',
            success: function(res) {
                myLon=res.longitude;
            }
        })
    },
    getUserInfo: function (cb) {
        var that = this
        if (this.globalData.userInfo) {
            typeof cb == "function" && cb(this.globalData.userInfo)
        } else {
            //调用登录接口
            wx.getUserInfo({
                withCredentials: false,
                success: function (res) {
                    that.globalData.userInfo = res.userInfo
                    typeof cb == "function" && cb(that.globalData.userInfo)
                }
            })
        }
    },
    ajaxRequest:function(url,method,data,successCallBack,failCallBack){
        var that=this;
        wx.request({
            url: this.globalData.serviceUrl+url,
            data: data,
            header: {
                'content-type': 'application/json'
            },
            success: function(ret) {
               successCallBack(ret.data);
            },
            fail:function (res) {
                if(typeof failCallBack =="undefined"){
                    alert("出错了，请稍后重试")
                }else{
                    failCallBack(res);
                }

            }
        })
    },
    globalData: {
        userInfo: null,
        serviceUrl: "http://app.jfl138.com/yii/web/api/",
        myLon:myLon,
        myLat:myLat
    },
})


